package com.didispace.chapter36.service;

import com.didispace.chapter36.entity.User;
import com.didispace.chapter36.mapper.UserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AsyncService {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private UserMapper userMapper;

    @Async
    @Transactional(rollbackFor = Exception.class, isolation = Isolation.REPEATABLE_READ)
    public void asyncMethod() {
        log.info("开始查询");
        // 根据姓名查询
        List<User> user = userMapper.findByName("李春天");
        log.info(user.toString());
    }
}
